//设置默认跟路径
axios.defaults.baseURL='http://ajax-api.itheima.net'
const list = document.querySelector('.top');
const renderData = async()=> {
    const {data:res} =await axios.get('/api/category/top')
    const {data} = res
   const newArr =  data.map(item=> {
        return axios.get('/api/category/sub',{params:{id:item.id}})
    })
    const pua = await Promise.all(newArr)
    list.innerHTML = pua.map(({data:item})=> {
      return `
      <li>
      <a href=" ">${item.data.name}</a>
      
      <img src="${item.data.picture}" alt="">
      <ul class="sub">
       ${item.data.children.map(item => {
return `
      <li>
      <a href="javascript:;">
       <span>${item.name}</span>
       <img src="${item.picture}" alt="">
      </a>
      </li>
`
}).join('')}

</ul>
</li>
`
    }).join('')
}
renderData()